package org.kpli.jak.net;

import java.io.*;

import java.net.*;

import java.util.Scanner;

public class Client {

	// IO streams

	private DataOutputStream toServer;

	private DataInputStream fromServer;

	public static void main(String[] args) {

		new Client();

	}

	public Client() {

		// Membuat scanner untuk masukan dari keyboard

		Scanner scanner = new Scanner(System.in);

		try {

			// Membuat socket untuk koneksi ke server

			Socket socket = new Socket("localhost", 8000);

			// Membuat input stream untuk menerima data dari server

			fromServer = new DataInputStream(

			socket.getInputStream());

			// Membuat output stream untuk mengirim data ke server

			toServer = new DataOutputStream(

			socket.getOutputStream());

			System.out.print("Enter an integer: ");

			Double radius = scanner.nextDouble();

			toServer.writeDouble(radius);

			toServer.flush();

			double area = fromServer.readDouble();

			System.out.print("Radius is " + radius + "\n");

			System.out.print("Area received from the server is "

			+ area + '\n');

		}

		catch (IOException ex) {

			System.out.print(ex.toString() + '\n');

		}

	}
}
